package com.corex.vinayak;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Intent;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

public class ExamActivity extends Activity {
	Chronometer examTimer;
	Button exam_submit;
	Button exam_questions;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.exam_layout);
		final Activity objThis = this;
		
		examTimer = (Chronometer) findViewById(R.id.exam_timer);
		exam_submit = (Button) findViewById(R.id.exam_submit);
		
		exam_submit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				//objThis.getWindow().getDecorView().findViewById(android.R.id.content).setAlpha((float) 0.1);
				
				LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
						.getSystemService(LAYOUT_INFLATER_SERVICE);

				View popupView = layoutInflater.inflate(
						R.layout.selectionbox_popup, null);
				final PopupWindow popupWindow = new PopupWindow(popupView,
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

				TextView popup_message = (TextView)popupView.findViewById(R.id.popup_message);
				popup_message.setText("Do you want to submit exam?");
				
				Button btnDismiss = (Button) popupView
						.findViewById(R.id.exam_submit_cancel);
				btnDismiss.setOnClickListener(new Button.OnClickListener() {

					@Override
					public void onClick(View v) {
						popupWindow.dismiss();
						objThis.getWindow().getDecorView().findViewById(android.R.id.content).setAlpha((float) 1.0);
					}
				});
				
				Button btnConfirm = (Button) popupView.findViewById(R.id.exam_submit_confirm);
				btnConfirm.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						popupWindow.dismiss();
						Intent intent = new Intent(ExamActivity.this, ResultActivity.class);
						startActivity(intent);
					}
				});
				popupWindow.showAtLocation(objThis.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
				popupWindow.showAsDropDown(exam_submit);
				
				/*
				LayoutInflater inflater = getLayoutInflater();
				View layout = inflater.inflate(R.layout.selectionbox_popup,
				                               (ViewGroup)findViewById(R.id.popup_layout));



				//TextView text = (TextView) layout.findViewById(R.id.text);
				//text.setText("Excellent !!!");
				//text.setBackgroundResource(R.drawable.right_ans);
				Toast toast = new Toast(getApplicationContext());
				toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
				toast.setDuration(Toast.LENGTH_SHORT);
				toast.setView(layout);
				toast.show();
				*/
			}
		});
		
		exam_questions = (Button) findViewById(R.id.exam_question_list);
		exam_questions.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ExamActivity.this, ExamQuestionListActivity.class);
				startActivity(intent);
			}
		});
		examTimer.setBase(SystemClock.elapsedRealtime());
		examTimer.start();
	}

	@Override
	public void onBackPressed() {

	}

	@Override
	protected void onPause() {
		super.onPause();
		/*
		Intent intent = getBaseContext().getPackageManager()
				.getLaunchIntentForPackage(getBaseContext().getPackageName());
		startActivity(intent);
		intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
		*/
	}

	@Override
	protected void onStop() {
		super.onStop();
		
	}
}
